package com.itheima.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.itheima.domain.db.Log;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

public interface LogMapper extends BaseMapper<Log> {
    //mybatis-plus只提供基本的增删改查 其他的都不提供  其他的需要自定义方法
    //今日的新增 和 今日的登陆
    @Select("SELECT COUNT(DISTINCT user_id) FROM tb_log WHERE TYPE=#{type} AND log_time=#{logTime}")
    public Integer findByLoginOrReg(@Param("type") String type ,@Param("logTime") String logTime);

    //活跃用户
    @Select("SELECT COUNT(DISTINCT user_id) FROM tb_log WHERE  log_time=#{logTime}")
    public Integer findActiveByLogTime( String logTime);

    //次日留存
    @Select("SELECT COUNT(DISTINCT user_id) FROM tb_log WHERE  log_time=#{today} AND user_id IN(\n" +
            "  SELECT DISTINCT user_id FROM tb_log WHERE TYPE='0102' AND log_time=#{yesterday})")
    public Integer findRetention(@Param("yesterday") String yesterday ,@Param("today")  String today);
}